package com.scm.java.net.sup.action;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.scm.entity.base.StoPerformance;
import com.scm.entity.system.SysRole;
import com.scm.java.net.system.action.BasicAction;
import com.scm.java.net.system.service.RoleManageService;
import com.scm.java.net.utils.StringUtils;

/**
 * 绩效管理Action
 * 
 * @author Administrator
 * 
 */
public class PerformanceAction extends BasicAction implements
		ModelDriven<StoPerformance>, Preparable {
	private StoPerformance performance;
	private RoleManageService roleManageService;
	private List<SysRole> roles = new ArrayList<SysRole>();

	/**
	 * 列表显示
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() throws Exception {
		getRoleList();
		paginatedQuery("drugStock.getPerformances");
		return "list";
	}

	/**
	 * 到达添加页面
	 * 
	 * @return
	 * @throws Exception
	 */
	public String toAdd() throws Exception {
		getRoleList();
		return "addPage";
	}

	/**
	 * 进行添加操作
	 * 
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception {
		performance.setId(StringUtils.uniqueKey());
		dao.addObj("drugStock.addPerformance", performance);
		return "succ";
	}

	/**
	 * 到达编辑页面
	 * 
	 * @return
	 * @throws SQLException
	 */
	public String toEdit() throws SQLException {
		getRoleList();
		Map paraMap=new HashMap();
		paraMap.put("performance", performance);
		performance = (StoPerformance) dao.queryList("drugStock.getPerformances", paraMap).get(0);
		return "editPage";
	}

	private void getRoleList() throws SQLException {
		Integer[] status = null;
		// 处理状态
		if (status == null) {
			status = new Integer[] { SysRole.ROLESTAT_ENABLE,
					SysRole.ROLESTAT_DISABLE };
		}
		Map paraMap = new HashMap();
		paraMap.put("status", status);
		roles = dao.queryList("role.getRole", paraMap);
	}

	/**
	 * 编辑绩效
	 * 
	 * @return
	 * @throws SQLException
	 */
	public String edit() throws SQLException {
		dao.editObj("drugStock.editPerformance", performance);
		return "succ";
	}

	public String del() throws SQLException {
		dao.del("drugStock.deletePerformance", performance);
		return "succ";
	}

	@Override
	public StoPerformance getModel() {
		// TODO Auto-generated method stub
		return performance;
	}

	public List<SysRole> getRoles() {
		return roles;
	}

	public void setRoles(List<SysRole> roles) {
		this.roles = roles;
	}

	public RoleManageService getRoleManageService() {
		return roleManageService;
	}

	public void setRoleManageService(RoleManageService roleManageService) {
		this.roleManageService = roleManageService;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		performance = new StoPerformance();
	}

	public StoPerformance getPerformance() {
		return performance;
	}

	public void setPerformance(StoPerformance performance) {
		this.performance = performance;
	}
}
